package bTree.LeetCode;

import java.util.*;

public class 用队列实现栈 {
    public Queue<Integer> queueA;
    public Queue<Integer> queueB;

    public MyStack() {
        queueA = new LinkedList<>();
        queueB = new LinkedList<>();
    }

    public void push(int x) {
        queueA.offer(x);
        while (!queueB.isEmpty()) {
            queueA.offer(queueB.poll());
        }
        Queue temp = queueA;
        queueA = queueB;
        queueB = temp;
    }

    public int pop() {
        return queueB.poll();
    }

    public int top() {
        return queueB.peek();
    }

    public boolean empty() {
        return queueB.isEmpty();
    }
}